package com.kpa.demo.ui.main.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.kpa.demo.R
import com.kpa.demo.data.model.Coming

/**
 *
 *
 * @author liliang
 */
class ComingAdapter(private val context: Context, private val comings: List<Coming>) :
    RecyclerView.Adapter<ComingAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val image: ImageView = view.findViewById(R.id.image)
        val mvName: TextView = view.findViewById(R.id.mv_name)
        val tvPeople: TextView = view.findViewById(R.id.tv_people)
        val tvProfessional: TextView = view.findViewById(R.id.tv_professional)
        val mvDec: TextView = view.findViewById(R.id.mv_dec)
        val mvDate: TextView = view.findViewById(R.id.mv_date)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(LayoutInflater.from(context).inflate(R.layout.coming_item, null))
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val coming = comings[position]
        val replaceImage = coming.img.replace("w.h", "100.200")
        Glide.with(context)
            .load(replaceImage)
            .into(holder.image)
        holder.mvName.text = coming.nm
        holder.tvPeople.text = coming.sc.toString()
        holder.tvProfessional.text = coming.mk.toString()
        holder.mvDec.text = coming.desc
        holder.mvDate.text = coming.pubDesc

    }

    override fun getItemCount() = comings.size
}